<?php
namespace TestAdmin\Controller;
use Think\Controller;

use Common\Controller\CommonActions\OrgnizerActionController as OrgC;
class AdminListController extends BaseController {




    public function AdminList()
    {
        if (IS_AJAX){
            $admins = M('admins')->select();

            $this->ajaxReturn($admins);
        }
        else{
            $this->display();
        }

        //var_dump($admins);
    }

    public function addNewAdmin()
    {
        if(IS_AJAX){
            $data['username'] = I('username');
            $data['password'] = I('passwd');

            $data['password'] = md5($data['password']);

            $admin = M('admins');


            $validate = array(
                array('username','require','用户名不能为空！',1),
                array('username','','用户已经存在',0,'unique',1),
            );


            $admin->setProperty("_validate",$validate);

            if ($admin->create($data)){

                if ($admin->add($data)){
                    $rs['msg'] = '新增管理员用户成功！';
                }
            }
            else{
                $rs['msg'] = $admin->getError();
            }
            $this->ajaxReturn($rs);
        }
    }


}